#include <all_wlib.h>
#pragma hdrstop

#include "int.h"

void __fastcall LoadNaviscope( HWND Handle, HOperation& rop, PRPeriod& h, CONSTSTR nm, AddUrlItem_p cb )
  {  CTParser   in;
     UrlInfo    it;
     bool       ask = true;
     bool       working = true;
     __int64    cn = 0;
     AnsiString error;

     if ( !in.Assign(nm) ) {
       AskMessage( Handle, NULL,
                   "Can not load \"%s\" file",
                   nm );
       return;
     }

     rop.SetAbort(true);
     while( working && in.NextGet() ) {
       ProcessMessages();

       //Check abort
       if ( rop.isAborted() &&
            AskYesNo( Handle, NULL, "Terminate loading?" ) ) {
         return;
       }

       //Refresh info
       if ( h.End() )
         rop.SetText( "Loading [%s]...\n\nLoaded: %I64u\nFile line: %d",
                      in.FName(), cn, in.GetY() );

       if ( !it.Load( in,error ) ) {
         if ( error.Length() && ask ) {
           switch( AskYesNoCancel( Handle, NULL,
                                   "Loaded: %I64u items, error: %s\n"
                                   "\nWhat you wana do ?\n"
                                   "YES: Abort loading file\n"
                                   "NO: Ignore current error\n"
                                   "CANCEL: Ignore all errors in this file\n",
                                   cn, error.c_str() ) ) {
             case IDYES: working = false;
                      break;
             case IDNO:
                      break;
             case IDCANCEL: ask = false;
                      break;
           }
         }
         in.GetToEOL();
         continue;
       } else {
        //Add item
        cn++;
        if ( !cb( it ) )
          return;
       }
     }
}